package uri.model.messenger;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import uri.model.MemberVO;
import uri.model.MessageVO;

@Repository
public class MessengerDAOImpl implements MessengerDAO {
	@Resource(name="sqlSessionTemplate")
	private SqlSessionTemplate sqlSessionTemplate;

	@Override
	public List<MemberVO> findFriend(HashMap<String, String> map) {
		return sqlSessionTemplate.selectList("messenger.findFriend",map);
	}

	@Override
	public void addFriend(HashMap<String, String> map) {
		sqlSessionTemplate.insert("messenger.addFriend",map);
	}

	@Override
	public List<MemberVO> friendList(HashMap<String,String> map) {
		return sqlSessionTemplate.selectList("messenger.friendList",map);
	}
	
	@Override
	public int getTotalFriends(String loginId) {
		return sqlSessionTemplate.selectOne("messenger.getTotalFriends",loginId);
	}

	@Override
	public List<MemberVO> memberList(HashMap<String, String> map) {
		return sqlSessionTemplate.selectList("messenger.memberList",map);
	}

	@Override
	public int getTotalMembers() {
		return sqlSessionTemplate.selectOne("messenger.getTotalMembers");
	}

	@Override
	public void deleteFriend(HashMap<String, String> map) {
		sqlSessionTemplate.delete("messenger.deleteFriend",map);
	}

	@Override
	public int isFriend(HashMap<String, String> map) {
		return sqlSessionTemplate.selectOne("messenger.isFriend",map);
	}

	@Override
	public void sendMessage(MessageVO msgvo) {
		sqlSessionTemplate.insert("messenger.sendMessage",msgvo);
	}
	
	@Override
	public void messageFileUpload(HashMap<String, String> map) {
		sqlSessionTemplate.insert("messenger.messageFileUpload",map);
	}

	@Override
	public List<MessageVO> sentMessageList(HashMap<String,String> map) {
		return sqlSessionTemplate.selectList("messenger.sentMessageList",map);
	}

	@Override
	public int getTotalSentMessage(String loginId) {
		return sqlSessionTemplate.selectOne("messenger.getTotalSentMessage",loginId);
	}

	@Override
	public List<MessageVO> receivedMessageList(HashMap<String, String> map) {
		return sqlSessionTemplate.selectList("messenger.receivedMessageList",map);
	}

	@Override
	public int getTotalReceivedMessage(String loginId) {
		return sqlSessionTemplate.selectOne("messenger.getTotalReceivedMessage",loginId);
	}
	
	@Override
	public List<HashMap<String,String>> getFileList(String msgNo) {
		return sqlSessionTemplate.selectList("messenger.getFileList",msgNo);
	}

	@Override
	public void sendChattingMessage(HashMap<String, String> map) {
		sqlSessionTemplate.insert("messenger.sendChattingMessage",map);
	}

	@Override
	public List<Map<String, String>> getChatting() {
		return sqlSessionTemplate.selectList("messenger.getChatting");
	}

	@Override
	public void deleteChattingTable() {
		sqlSessionTemplate.delete("messenger.deleteChattingTable");
	}

}
